package com.hspedu.collection_;

/**
 * @author 谷其昊
 * @version 1.0
 * @date 2022/2/7
 * @time 16:45
 */
public class TestLinkedList {
    public static void main(String[] args) {
        Node jack = new Node("jack");
        Node bob = new Node("bob");
        Node lucy = new Node("lucy");

        jack.next = bob;
        bob.next = lucy;

        lucy.pre = bob;
        bob.pre = jack;

        Node first = jack;
        Node last = lucy;

        while (true){
            if (first == null){
                break;
            }
            System.out.println(first);
            first = first.next;
        }

        Node pop = new Node("pop");
        jack.next = pop;
        pop.next = bob;

        pop.pre = jack;
        bob.pre = pop;
        System.out.println("==============");
        first = jack;
        while (true){
            if (first == null){
                break;
            }
            System.out.println(first);
            first = first.next;
        }

        System.out.println("================");

        while (true){
            if (last == null){
                break;
            }
            System.out.println(last);
            last = last.pre;
        }
    }
}

class Node{
    public Node next;
    public Node pre;
    private Object item;

    public Node(Object item) {
        this.item = item;
    }

    @Override
    public String toString() {
        return "Node{" +
                "item=" + item +
                '}';
    }
}
